import axios from 'axios'
import { getFromLocalStorage } from './store-data'


const BASE_URL = 'http://localhost:9999'

const token = getFromLocalStorage('token') || {}

const request = axios.create({ timeout: 5000, baseURL: BASE_URL })

request.interceptors.request.use((config) => {
  if(token) config.headers.Authorization = `Bearer ${token}`;
  return    config;
},(err) => Promise.reject(err))

request.interceptors.response.use((res) => res.data, (err) => Promise.reject(err));

export default request;
